﻿''' <summary>
''' Summary of NavFx Application
''' </summary>
Partial Public Class App
	Inherits Global.NavFx.Application


#Region "Constructors"

	''' <summary>
	''' Default constructor
	''' </summary>
	Public Sub New()
		MyBase.New()
		InitializeComponent()
	End Sub

#End Region

#Region "Event handlers"

	''' <summary>
	''' Load the main page when the application starts
	''' </summary>
	''' <param name="sender"></param>
	''' <param name="e"></param>
	Private Sub Application_Startup(ByVal sender As Object, ByVal e As StartupEventArgs) Handles Me.Startup

		'Load the main empty page that acts
		'as a shell for all content
		Me.RootVisual = New Shell()

		'set up the navigator with the default
		'transition handler, important to do this
		'before loading any NavFx pages so setting
		'a default now ensures one is available
		'passing the application itself as the target
		'for the simple transitor, which check the
		'RootVisual for IHostPage if it is available
		'the SetContent method will be used to display
		'the page
		MyBase.GetNavigator().Transitor = New SimpleTransitor(Application.Current)

		Application.Current.WriteOutput(vbCrLf & "In Application_Startup of App.xaml.vb executing...")
		Application.Current.WriteOutput("Me.GetNavigator().Transitor = New SimpleTransitor(App.Current)")

	End Sub

	''' <summary>
	''' Handles cleanup when the application exits
	''' </summary>
	Private Sub Application_Exit(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Exit


	End Sub

	''' <summary>
	''' Global handler for unhandled exceptions
	''' </summary>
	Private Sub Application_UnhandledException(ByVal sender As Object, ByVal e As ApplicationUnhandledExceptionEventArgs) Handles Me.UnhandledException

		' If the app is running outside of the debugger then report the exception Imports
		' the browser's exception mechanism. On IE Me will display it a yellow alert 
		' icon in the status bar and Firefox will display a script error.
		If Not System.Diagnostics.Debugger.IsAttached Then


			' NOTE: This will allow the application to continue running after an exception has been thrown
			' but not handled. 
			' For production applications Me error handling should be replaced with something that will 
			' report the error to the website and stop the application.
			e.Handled = True

			Try

				Dim errorMsg As String = e.ExceptionObject.Message + e.ExceptionObject.StackTrace
				errorMsg = errorMsg.Replace(""""c, "\"c).Replace("\r\n", "\n")

				System.Windows.Browser.HtmlPage.Window.Eval("throw New Error(""Unhandled Error in NavFx Application " + errorMsg + """);")
			Catch

			End Try
		End If
	End Sub

#End Region
End Class
